package com.zpark.it.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zpark.it.pojo.Clazz;
import com.zpark.it.service.ClazzService;
import com.zpark.it.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title: ClazzController
 * @Author Charles
 * @Package com.zpark.it.controller
 * @Date 2023/7/31 15:31
 */
@Api(tags = "班级控制器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    /**
     * 分页查询带条件、查询班级信息
     * @param pageNo
     * @param pageSize
     * @param clazz
     * @return
     */
    @ApiOperation("分页带条件查询班级信息")
    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(@ApiParam("分页查询的页码数")@PathVariable("pageNo") Integer pageNo,
                                @ApiParam("分页查询的页大小")@PathVariable("pageSize") Integer pageSize,
                                @ApiParam("分页查询的查询条件")Clazz clazz){
        Page<Clazz> page=new Page<>(pageNo,pageSize);
        IPage<Clazz> iPage = clazzService.getClazzsByOpr(page, clazz);
        System.out.println(iPage);
        return Result.ok(iPage);

    }

    /**
     * 增加或者修改班级
     * @param clazz
     * @return
     */
    //saveOrUpdateClazz
    @ApiOperation("增加或者修改班级")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@ApiParam("json格式的班级信息")@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }

    @ApiOperation("删除多个和多个班级信息")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazzIds(@ApiParam("要删除的多个班级的ID的json数组")@RequestBody List<Integer> ids){
          clazzService.removeByIds(ids);
          return Result.ok();
    }
    @ApiOperation("查询所有班级信息")
    @GetMapping("/getClazzs")
    public Result getClazz(){
        List<Clazz> clazz = clazzService.getClazzs();
        return Result.ok(clazz);
    }
}
